#pragma once
#include <list>
#include "Event.h"
#include "types.h"

class SkCanvas;

class View
{
public:
	static const uint32 STATUS_NORMAL  = 0x00000001;
	static const uint32 STATUS_FOCUS   = 0x00000002;
	static const uint32 STATUS_DISABLE = 0x00000004;
	static const uint32 STATUS_VISIBLE = 0x00000008;


	View(View* parent);
	virtual ~View();

	void setBolder(unsigned int x, unsigned int y, unsigned int width, unsigned int height);
	unsigned int X();
	unsigned int Y();
	unsigned int Width();
	unsigned int Height();

	void setID(uint32 id);
	uint32 getID();

	virtual bool updateLayout();

	bool addChild(View* view);
	bool remoteChild(View* view);

	void setStatus(uint32 status);
	uint32 getStatus();

	void setParent(View* parent);
	View* getParent();

	virtual bool onPaint(SkCanvas* canvas);

	virtual View* FindTopViewInPoint(int x, int y);

	virtual bool isLockFocus() { return true; }

	virtual void mouseEntry();

	virtual void mouseLeave();

	virtual void gotFocus();

	virtual void loseFocus();

	virtual void setText(std::wstring& text);

	virtual std::wstring getText();

	View* getViewById(uint32 id);

	void updateView();
protected:
	virtual bool paint(SkCanvas* canvas);
	bool paintBorder(SkCanvas* canvas);
	virtual bool paintFocus(SkCanvas* canvas);


	/************************************************************************/
	/* handle action                                                        */
	/************************************************************************/
	friend class EventManager;

	virtual bool processKeyEvent(KeyEvent& event);

	virtual bool processRawKeyEvent(KeyEvent& event);

	virtual bool processMouseEvent(MouseEvent& event);


private:
	unsigned int m_x;
	unsigned int m_y;
	unsigned int m_width;
	unsigned int m_height;

	uint32 m_id;

	unsigned int m_top_pad;
	unsigned int m_left_pad;

	uint32 m_status;

	View* m_parent;
	std::wstring m_text;
protected:
	std::list<View *> m_childViews;

};

